package operation;

import book.book;
import book.booklist;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 666
 * Date: 2022-11-18
 * Time: 20:39
 */
public class delateoperation implements Ioper{
    @Override
    public void work(booklist book) {
        System.out.println("请输入要删除的书名");
        Scanner scanner = new Scanner(System.in);
        String name=scanner.nextLine();
        int cur=book.getBookSize();
        int index=-1;
        for (int i = 0; i < cur; i++) {
            book book1=  book.getBooks(i);
            if(book1.getName().equals(name)){
                index=i;
                break;
            }else {
                System.out.println("没有找到要删除的书");
                break;
            }
        }
        for (int j = index; j < cur-1; j++) {
            book book2=book.getBooks(j+1);
            book.setBooks(j,book2);
        }
        book.setBookSize(cur-1);
        book.setBooks(cur-1,null);
        System.out.println("删除成功");
    }
}
